package org.example.common.util;

import java.time.LocalDateTime;

public class DateUtil {

    public static LocalDateTime firstDayOfLastMonth() {
        //返回上个月第一天第一毫秒
        return LocalDateTime.now().minusMonths(1)
                .withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
    }
    public static int lastDayOfMont(LocalDateTime time) {
        return time.withDayOfMonth(time.getMonth().length(time.toLocalDate().isLeapYear()))
                .withHour(23).withMinute(59).withSecond(59).withNano(999999999).getDayOfMonth();
    }

    public static int milliSecondBetween(LocalDateTime a, LocalDateTime b) {
        return (int) (b.toInstant(java.time.ZoneOffset.of("+8")).toEpochMilli() - a.toInstant(java.time.ZoneOffset.of("+8")).toEpochMilli());
    }

}
